package com.example.leetcode.trainingcamp.week4.Thursday;


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 输入一个链表的头节点，从尾到头反过来返回每个节点的值（用数组返回）。
 *
 *
 *
 * 示例 1：
 *
 * 输入：head = [1,3,2]
 * 输出：[2,3,1]
 */
public class Offer06 {
    List<Integer> list = new ArrayList<>();
    public int[] reversePrint(ListNode head) {
        reverse(head);
        int[] result = new int[list.size()];
        for (int i = 0;i<list.size();i++) {
            result[i] = list.get(i);
        }
        return result;
    }
   void reverse(ListNode head){
        if (head == null) {
            return;
        }
        reverse(head.next);
        list.add(head.val);
   }
}


class ListNode {
    int val;
    ListNode next;
    ListNode() {}
    ListNode(int val) { this.val = val; }
    ListNode(int val, ListNode next) { this.val = val; this.next = next; }
}